package LeetCode;

import java.util.Scanner;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/5/7.
// 
public class 两数相除 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int dividend = scan.nextInt();
        int divisor = scan.nextInt();
        System.out.println(divide(dividend,divisor));
    }

//    public static int divide(int dividend, int divisor) {
//        if(divisor == 1) return dividend;
//        if(divisor==-1){
//            if(dividend == -Math.pow(2,31)) return (int) (Math.pow(2,31) - 1);
//            else return -dividend;
//        }
//        int flag = -1;
//        if((dividend > 0 && divisor > 0) || (dividend < 0 && divisor < 0))flag = 1;
//        long dd = Math.abs((long)dividend);
//        long ds = Math.abs((long)divisor);
//        long res = 0;
//        while (dd >= ds){
//            dd-=ds;
//            res++;
//        }
//        if(flag == 1){
//            if(res > Integer.MAX_VALUE)return Integer.MAX_VALUE;
//            return (int) res;
//        } else{
//            if(-res < Integer.MIN_VALUE)return Integer.MIN_VALUE;
//            return (int) -res;
//        }
//    }
public static int divide(int dividend, int divisor) {
    if(dividend==Integer.MIN_VALUE&&divisor==-1) return Integer.MAX_VALUE;
    if(dividend==Integer.MIN_VALUE&&divisor==1) return Integer.MIN_VALUE;
    if(dividend>0) return -divide(-dividend, divisor);
    if(divisor>0) return -divide(dividend, -divisor);
    if(dividend>divisor) return 0;
    int res =1,temp =divisor;
    while((dividend-temp)<temp){
        temp+=temp;
        res+=res;
    }
    return res+divide(dividend-temp,divisor);
}
}
